/*
 * Kerning Gachapon
 * @author: DejaVu
*/

void npc(Player @player, NPC @npc) {
	int state = npc.getState();
	const int [] items = {1002130,1040042,1040094,1322052,2000005,2022113,1302001,2040106,1332002};
	int selection = npc.getSelected();
	if(state == 0){
		if(player.getItemAmount(5220000) > 0){
			npc.addText("You may use Gachapon. Would you like to use your Gachapon ticket?");
			npc.sendYesNo();
		} else {
			npc.addText("Welcome to the Kerning Gachapon. How may I help you?\r\n\r\n#L0#What is Gachapon?#l\r\n#L1#Where can you buy Gachapon tickets?#l");
			npc.sendSimple();
		}
	}
	else if(state == 1){
		if(player.getItemAmount(5220000) > 0){
			if(npc.getSelected() == YES){
				const int amt = 9;
				int prize = random(amt);
				player.giveItem(5220000, -1);
				player.giveItem(items[prize], 1);
				npc.end();
			} else {
				npc.end();
			}
		} else {
			if(selection == 0){
				npc.addText("Play Gachapon to earn rare scrolls, equipment, chairs, mastery books, and other cool items! All you need is a #bGachapon Ticket#k to be the winner of a random mix of items.");
				npc.sendOK();
				npc.end();
			}
			else if(selection == 1){
				npc.addText("Gachapon Tickets are available in the #rCash Shop#k and can be purchased using NX or Maple Points. Click on the red SHOP at the lower right hand corner of the screen to visit the #rCash Shop #kwhere you can purchase tickets.");
				npc.sendOK();
				npc.end();
			} else {
				npc.end();
			}
		}
	} else {
		npc.end();
	}
}